const app = getApp();
const log =require('../../log.js');
const util=require('../../util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        more:1,
        list:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that =this;
        var userInfo=wx.getStorageSync('userInfo');
        that.setData({
            platform:app.globalData.platform,    
            userInfo:userInfo,
             width:app.globalData.windowWidth,
            height:app.globalData.windowHeight,
            statusBarHeight:app.globalData.statusBarHeight,
            navHeight:app.globalData.navHeight,
            marginTop:app.globalData.navTitleTop,
            domain:app.globalData.domain
          })
    },
    goBack:function(){
        wx.navigateBack();
      },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getIndex(1);
      },
      getIndex:function(page){
          let that = this; 
          var userInfo=wx.getStorageSync('userInfo');  
          var limit=10;     
          wx.request({
            url: app.globalData.domain+'pay/index',
            data:{from:1,user_id:userInfo.id,page:page,limit:limit},
            success:res=>{             
                var data=res.data;
                console.log(data);
               // var my=data.my
                //var mylen=my.length; 
                var list=that.data.list;
                list=list.concat(data.list)
              that.setData({
               shareTitle:data.shareTitle,
               shareLogo:data.shareLogo,
                list:list,
                total:data.total,
                refund:data.refund,
                page:data.page,
                more:data.more
             
              })
            }
        })
      },
     refund(e){
         console.log(e);
         var id=e.currentTarget.dataset.id
         var transaction_id=e.currentTarget.dataset.transaction_id;
         var userInfo=wx.getStorageSync('userInfo');
         var page=this.data.page;
         let that=this;
         wx.request({
            url: app.globalData.domain+'pay/refund',
            data:{from:1,user_id:userInfo.id,id:id,transaction_id:transaction_id},
            success:res=>{    
               // console.log(res);
               var data=res.data;
               if(data.code=200){
                    that.showModels(data.desc)
                    that.getIndex(1);
               }else{
                    that.showModels(data.desc)
                    that.getIndex(1);
               }
            }
        });

     },
     showModals(msg){
        wx.showModal({
            title: '系统提示',
            content:msg,
            success:function(res){
                return false;
            }
        })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        var more=this.data.more;
        var page =this.data.page;
        if(more==1){
            page=parseInt(page)+1;
            this.getIndex(page)
        }else{
            console.log('no more');
        }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})